Red Hat Enterprise Linux 7 Implementation

File System Navigation

Module Topics

  • Linux File System

  • Important Linux Directories

  • Symbolic Link Directories

  • File Management

  • Create Directories

  • Copy, Move, and Remove Files and Directories

  • Create Hard Links

  • Create Soft Links

Linux File System

File System Hierarchy
  • File systems organized into a single inverted tree of directories

  • Root of tree is at top of hierarchy

    • Branches of directories and subdirectories are below

RHEL7 filesystem hierarchy

Linux File System

Directory Structure and Naming
  • / is root directory at top of file system hierarchy

  • / character also used as directory separator in file names

    • Example: etc subdirectory of / is /etc

    • Example: issue file within /etc is /etc/issue

  • Subdirectories of / are used for standard purposes to organize files

    • Example: In / root directory, /boot stores files needed to boot system

Linux File System

File System Terms
  • Static: Content that remains unchanged until explicitly edited or reconfigured

  • Dynamic or variable: Content that is modified or appended by active processes

  • Persistent: Content, particularly configuration settings, that remains after a reboot

  • Runtime: Process- and system-specific content and attributes that are cleared during a reboot

Important Linux Directories

Location

Purpose

/usr

Installed software, shared libraries, include files, and static read-only program data. Important subdirectories include:

  • /usr/bin: User commands

  • /usr/sbin: System administration commands

  • /usr/local: Locally customized software

/etc

Configuration files specific to system.

/var

Variable data specific to system that should persist between boots. Under /var are files that dynamically change.

Examples: Databases, cache directories, log files, printer-spooled documents, and website content.

/run

Runtime data for processes started since last boot. Includes process ID files and lock files. Contents of /run is recreated on reboot.

/run consolidates /var/run and /var/lock from older versions of Red Hat Enterprise Linux.

/home

Where regular users store personal data and configuration files.

/root

Home directory for root, the administrative superuser.

/tmp

World-writable space for temporary files. Files that are not accessed, changed, or modified for 10 days are deleted automatically.

/var/tmp is also a temporary directory in which files that have not been accessed, changed, or modified in more than 30 days are deleted automatically.

/boot

Contains files needed to start boot process.

/dev

Contains special device files that are used by system to access hardware.

File Management

This table describes common file management commands and how they are used in single-source and multiple-source situations.

Task

Single Source (note)

Multiple Source (note)

Copy file

cp file1 file2

cp file1 file2 file3 dir (5)

Move file

mv file1 file2 (1)

mv file1 file2 file3 dir (4)

Remove file

rm file1

rm -f file1 file2 file3 (5)

Create directory

mkdir dir

mkdir -p par1/par2/dir (6)

Copy directory

cp -r dir1 dir2 (2)

cp -r dir1 dir2 dir3 dir4 (4)

Move directory

mv dir1 dir2 (3)

mv dir1 dir2 dir3 dir4 (4)

Remove directory

rm -r dir1 (2)

rm -rf dir1 dir2 dir3 (5)

(1)The result is a rename. (2)The recursive option is required to process a source directory. (3)If dir2 exists, the result is a move. If dir2 does not exist, the result is a rename. (4)The last argument must be a directory. (5)Use caution with the force option. You are not prompted to confirm your action. (6)Use caution with the create-parent option. Typing errors are not reported or corrected.

Create Directories

  • Use mkdir to create directories and subdirectories

  • Error conditions:

    • Name already exists

    • Parent directory does not exist

  • Use -p to create missing parent directories for requested destination

    • Spelling and typing mistakes create unintended directories without generating error messages

  • Example: mkdir error condition

    [student@desktop1 ~]$ mkdir Video/Watched
    mkdir:cannot create directory `Video/Watched': No such file or directory

Create Multiple Directories

[student@desktop1 ~]$ mkdir Videos/Watched
[student@desktop1 ~]$ cd Documents
[student@desktop1 Documents]$ mkdir ProjectX ProjectY
[student@desktop1 Documents]$ mkdir -p Thesis/Chapter1 Thesis/Chapter2 Thesis/Chapter3
[student@desktop1 Documents]$ cd
[student@desktop1 ~]$ ls -R Videos Documents
Documents:
ProjectX  ProjectY  Thesis  thesis_chapter1.odf  thesis_chapter2.odf

Documents/ProjectX:

Documents/ProjectY:

Documents/Thesis:
Chapter1  Chapter2  Chapter3

Documents/Thesis/Chapter1:

Documents/Thesis/Chapter2:

Documents/Thesis/Chapter3:

Videos:
blockbuster1.ogg  blockbuster2.ogg  Watched

Videos/Watched:

[student@desktop1 ~]$

Copy Files

  • Use cp to copy one or more files to new, independent files

    • Copy file to new file in current directory or another

    • Copy multiple files to another directory

  • New file names must be unique

    • If new file name is not unique, cp overwrites existing file

      [student@desktop1 ~]$ cd Videos
      [student@desktop1 Videos]$ cp blockbuster1.ogg blockbuster3.ogg
      [student@desktop1 Videos]$ ls -l
      total 0
      -rw-rw-r--. 1 student student    0 Feb  8 16:3 blockbuster1.ogg
      -rw-rw-r--. 1 student student    0 Feb  8 16:4 blockbuster2.ogg
      -rw-rw-r--. 1 student student    0 Feb  8 19:2 blockbuster3.ogg
      drwxrwxr-x. 2 student student 4096 Feb  8 23:5 Watched
      [student@desktop1 Videos]$

Copy Multiple Files

  • When copying multiple files with one command, last argument must be a directory

    • Copied files retain original names in new directory

    • Conflicting file names at destination result in overwritten files

    • To prevent overwriting, multi-file cp ignores directories specified as source

  • Use -r to copy non-empty directories

Copy Multiple Files

[student@desktop1 Videos]$ cd ../Documents
[student@desktop1 Documents]$ cp thesis_chapter1.odf thesis_chapter2.odf Thesis ProjectX
cp:omitting directory `Thesis'
[student@desktop1 Documents]$ cp -r Thesis ProjectX
[student@desktop1 Documents]$ cp thesis_chapter2.odf Thesis/Chapter2/
[student@desktop1 Documents]$ ls -R
.:
ProjectX  ProjectY  Thesis  thesis_chapter1.odf  thesis_chapter2.odf

./ProjectX:
Thesis  thesis_chapter1.odf  thesis_chapter2.odf

./ProjectX/Thesis:

./ProjectY:

./Thesis:
Chapter1  Chapter2  Chapter3

./Thesis/Chapter1:

./Thesis/Chapter2:
thesis_chapter2.odf

./Thesis/Chapter3:
[student@desktop1 Documents]$

Move Files

  • Use mv to rename files in same directory or relocate files to new directory

  • File content remains unchanged

  • To move files to different file system, create new file by copying and then delete source file

    • Large files may take longer to move

Move Files

[student@desktop1 Videos]$ cd ../Documents
[student@desktop1 Documents]$ ls -l
total 0
-rw-rw-r--. 1 student student    0 Feb  8 16:4 thesis_chapter1.odf
-rw-rw-r--. 1 student student    0 Feb  8 16:4 thesis_chapter2.odf
[student@desktop1 Documents]$ mv thesis_chapter2.odf thesis_chapter2_reviewed.odf
[student@desktop1 Documents]$ mv thesis_chapter1.odf Thesis/Chapter1
[student@desktop1 Documents]$ ls -lR
.:
total 16
drwxrwxr-x. 2 student student 4096 Feb 11 11:8 ProjectX
drwxrwxr-x. 2 student student 4096 Feb 11 11:5 ProjectY
drwxrwxr-x. 5 student student 4096 Feb 11 11:6 Thesis
-rw-rw-r--. 1 student student    0 Feb 11 11:4 thesis_chapter2_reviewed.odf

./ProjectX:
total 0
-rw-rw-r--. 1 student student 0 Feb 11 11:8 thesis_chapter1.odf
-rw-rw-r--. 1 student student 0 Feb 11 11:8 thesis_chapter2.odf

./ProjectX/Thesis:
total 0

./ProjectY:
total 0

./Thesis:
total 12
drwxrwxr-x. 2 student student 4096 Feb 11 11:9 Chapter1
drwxrwxr-x. 2 student student 4096 Feb 11 11:6 Chapter2
drwxrwxr-x. 2 student student 4096 Feb 11 11:6 Chapter3

./Thesis/Chapter1:
total 0
-rw-rw-r--. 1 student student 0 Feb 11 11:4 thesis_chapter1.odf

./Thesis/Chapter2:
total 0
-rw-rw-r--. 1 student student 0 Feb 11 11:4 thesis_chapter2.odf

./Thesis/Chapter3:
total 0
[student@desktop1 Documents]$

Remove Files

  • Default syntax for rm deletes files but not directories

  • To delete directories and subdirectories, use -r

  • To receive prompt for each deletion, use -i

  • To force deletion without prompts, use -f

There is no undelete command or trash bin from which to restore.
[student@desktop1 Documents]$ pwd
/home/student/Documents
[student@desktop1 Documents]$ rm thesis_chapter2_reviewed.odf
[student@desktop1 Documents]$ rm Thesis/Chapter1
rm:cannot remove `Thesis/Chapter1': Is a directory
[student@desktop1 Documents]$ rm -r Thesis/Chapter1
[student@desktop1 Documents]$ ls -l Thesis
total 8
drwxrwxr-x. 2 student student 4096 Feb 11 12:7 Chapter2
drwxrwxr-x. 2 student student 4096 Feb 11 12:8 Chapter3
[student@desktop1 Documents]$ rm -ri Thesis
rm:descend into directory `Thesis'? y
rm:descend into directory `Thesis/Chapter2'? y
rm:remove regular empty file `Thesis/Chapter2/thesis_chapter2.odf'? y
rm:remove directory `Thesis/Chapter2'? y
rm:remove directory `Thesis/Chapter3'? y
rm:remove directory `Thesis'? y
[student@desktop1 Documents]$

Remove Directories

  • To delete only empty directories, use rmdir

  • Removed directories cannot be undeleted

    [student@desktop1 Documents]$ pwd
    /home/student/Documents
    [student@desktop1 Documents]$ rmdir  ProjectY
    [student@desktop1 Documents]$ rmdir  ProjectX
    rmdir:failed to remove `ProjectX': Directory not empty
    [student@desktop1 Documents]$ rm -r ProjectX
    [student@desktop1 Documents]$ ls -lR
    .:
    total 0
    [student@desktop1 Documents]$
References
  • Man pages: cp(1), mkdir(1), mv(1), rm(1), and rmdir(1)

Summary

  • Linux File System

  • Important Linux Directories

  • Symbolic Link Directories

  • File Management

  • Create Directories

  • Copy, Move, and Remove Files and Directories

  • Create Hard Links

  • Create Soft Links

Module Completion

Nice job!

Click the button below to complete this module of the course: